package com.pricl.frame.core;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p>
 * 抽象App类 应用框架需要继承该类
 * </p>
 * 
 * @author cheng(iknoweth@yahoo.com)
 * @date 2016-5-4 下午10:17:59
 */
public abstract class App {

	Logger logger = LoggerFactory.getLogger(App.class);

	public abstract SimpleAuthorizationInfo getInfo(Long key);
	
	// public SimpleAuthorizationInfo getInfo(String key) {
	// if (key == null || key.equals("")) {
	// return null;
	// }
	// SimpleAuthorizationInfo authorizationInfo=authorizationInfos.get(key);
	// if(authorizationInfo==null){
	// authorizationInfo=new SimpleAuthorizationInfo();
	// }
	// return authorizationInfo;
	// }

	/**
	 * 
	 * @param user
	 */
	// public void setContextUser(User user) {
	// HttpServletRequest request = ((ServletRequestAttributes)
	// RequestContextHolder.getRequestAttributes())
	// .getRequest();
	// Helper.setUser(request, user);
	// }

	/**
	 * 
	 * @param key
	 * @param value
	 */
	public void setSession(Object key, Object value) {
		Subject currentUser = SecurityUtils.getSubject();
		if (null != currentUser) {
			Session session = currentUser.getSession();
			logger.info("Session默认超时时间为[" + session.getTimeout() / 1000 + "]秒");
			if (null != session) {
				session.setAttribute(key, value);
			}
		}
	}

	public final Map<String, String> getPrefixPerms() {
		Map<String, String> perms = new HashMap<String, String>();
		setPrefixPerms(perms);
		return perms;
	}

	public final Map<String, String> getSuffixPerms() {
		Map<String, String> perms = new HashMap<String, String>();
		setSuffixPerms(perms);
		return perms;
	}

	public abstract void setPrefixPerms(Map<String, String> perms);

	public abstract void setSuffixPerms(Map<String, String> perms);

	public abstract Map<String, String> getDefinePerms();

	public abstract User findForLogin(String username, String password, String salt);

}
